package com.suzhiliang.springbootlesson.globalExceptionDeal;

import org.springframework.web.bind.annotation.*;

/**
 * Copyright (C), 2015-2019, XXX有限公司
 *
 * @ClassName: RestExceptionHandler
 * @Author: xmm
 * @Date: 2019/8/21 15:21
 * @Description: 全局异常处理，配置全局异常Handler
 * @Version 1.0
 */
@ControllerAdvice(annotations = RestController.class) //@ControllerAdvice注解是用来配置控制器通知
@ResponseBody
public class RestExceptionHandler {
    /**
     * 默认统一异常处理方法
     * @param e 默认Exception异常对象
     */
    @ExceptionHandler
    @ResponseStatus
    public ApiResult runtimeExceptionHandler(Exception e){
        return ApiResultGenerator.errorResult(e.getMessage(),e);
    }
}
